

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.hibernate.Session;

import app.AppWorkSession;
import app.datavalue.DeliveryRepMsgInfo;
import app.datavalue.HandlingInfo;
import app.datavalue.MessageStatus;
import app.datavalue.MsgInfo;
import app.model.HibernateUtils;
import app.model.MessageStorage;
import app.model.StorageResult;


public class TestHibernate 
{

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		BasicConfigurator.configure();
		
		/*
		Session session = HibernateUtils.currentSession();
		
		session.beginTransaction();
		session.getTransaction().commit();
		HibernateUtils.closeSession();
		*/
		MessageStorage msgStorage = new MessageStorage();
		
		MsgInfo msgInfo = new MsgInfo();
		//msgInfo.setId(9);
		msgInfo.setBody("test hibernate ");
		msgInfo.setScrAddr("scrAddr");
		msgInfo.setDestAddr("dstAddr");
		msgInfo.setWorkSessionId( AppWorkSession.getInstace().getCurrentSessionId() );
		msgInfo.setStatus(MessageStatus.UNASSIGNED);
		msgStorage.updateInMsg(msgInfo);
		
		
		msgInfo.setBody("test hibernate update pp");
		msgStorage.updateInMsg(msgInfo);
		
		
		DeliveryRepMsgInfo devRepMsgInfo = new DeliveryRepMsgInfo();
		
		
		devRepMsgInfo.setExternalId("extrid");
		
		msgStorage.updateDeliveryReportInfo(devRepMsgInfo);
		
		devRepMsgInfo.setExternalId("extrid updated");
		
		msgStorage.updateDeliveryReportInfo(devRepMsgInfo);
		
		DeliveryRepMsgInfo loadedRepInfo = msgStorage.findDeliveryRepMsgInfoByExternalId("extrid updated");
		
		Logger.getLogger( TestHibernate.class ).log( Priority.DEBUG , loadedRepInfo);
		
		
		StorageResult<MsgInfo> notProccInNonCurrSessionIter = msgStorage.getUnProcIncMsgsNonCurrWorkSession();
		
		Logger.getLogger( TestHibernate.class ).log( Priority.DEBUG  , " start processed" );
		for ( MsgInfo procmsgInfo : notProccInNonCurrSessionIter.getResult() )
			Logger.getLogger( TestHibernate.class ).log( Priority.DEBUG , procmsgInfo.getId());
		Logger.getLogger( TestHibernate.class ).log( Priority.DEBUG  , "end processed" );
		
		
		HandlingInfo hiInfo = msgStorage.findHandlingInfo("file2get");
		
		Logger.getLogger( TestHibernate.class ).log( Priority.DEBUG  , "hiInfo " + hiInfo.getResponse() );
		
		/*
		Cat cat = new Cat();
		
		cat.setName( "Tom" );
		cat.setSex('F');
		cat.setWeight( 2.1f );
		
		session.save( cat );
		
		session.getTransaction().commit();
		
		session.beginTransaction();
		cat.setName( "Tom2" );
		
		session.save( cat );
		session.getTransaction().commit();
		
		HibernateUtils.closeSession();
		*/
		
	}

}
